﻿@model Nop.Plugin.Shipping.FixedOrByWeight.Models.ShippingByWeightModel
@using Nop.Web.Framework;

@Html.ValidationSummary(false)
@Html.HiddenFor(model => model.Id)

@if (ViewBag.RefreshPage == true)
{
    <script type="text/javascript">
        try {window.opener.document.forms['@(ViewBag.formId)'].@(ViewBag.btnId).click();}
        catch (e){}
        window.close();
    </script>
}

<script type="text/javascript">
    $(document).ready(function () {
        $("#@Html.FieldIdFor(model => model.CountryId)").change(function () {
            var selectedItem = $(this).val();
            var ddlStates = $("#@Html.FieldIdFor(model => model.StateProvinceId)");
            $.ajax({
                cache: false,
                type: "GET",
                url: "@(Url.Action("GetStatesByCountryId", "Country", new RouteValueDictionary { { "area", "Admin" } }))",
                data: { "countryId": selectedItem, "addAsterisk": "true" },
                success: function (data) {
                    ddlStates.html('');
                    $.each(data, function (id, option) {
                        ddlStates.append($('<option></option>').val(option.id).html(option.name));
                    });
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert('Failed to retrieve states.');
                }
            });
        });
    });
</script>

<div class="panel-group">
    <div class="panel panel-default panel-popup">
        <div class="panel-body">
            <div class="form-group" @(Model.AvailableStores.SelectionIsNotPossible() ? Html.Raw("style=\"display:none\"") : null)>
                <div class="col-sm-3">
                    @Html.NopLabelFor(model => model.StoreId)
                </div>
                <div class="col-sm-9">
                    @Html.NopDropDownListFor(model => model.StoreId, Model.AvailableStores)
                    @Html.ValidationMessageFor(model => model.StoreId)
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-3">
                    @Html.NopLabelFor(model => model.WarehouseId)
                </div>
                <div class="col-sm-9">
                    @Html.NopDropDownListFor(model => model.WarehouseId, Model.AvailableWarehouses)
                    @Html.ValidationMessageFor(model => model.WarehouseId)
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-3">
                    @Html.NopLabelFor(model => model.CountryId)
                </div>
                <div class="col-sm-9">
                    @Html.NopDropDownListFor(model => model.CountryId, Model.AvailableCountries)
                    @Html.ValidationMessageFor(model => model.CountryId)
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-3">
                    @Html.NopLabelFor(model => model.StateProvinceId)
                </div>
                <div class="col-sm-9">
                    @Html.NopDropDownListFor(model => model.StateProvinceId, Model.AvailableStates)
                    @Html.ValidationMessageFor(model => model.StateProvinceId)
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-3">
                    @Html.NopLabelFor(model => model.Zip)
                </div>
                <div class="col-sm-9">
                    @Html.NopEditorFor(model => model.Zip)
                    @Html.ValidationMessageFor(model => model.Zip)
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-3">
                    @Html.NopLabelFor(model => model.ShippingMethodId)
                </div>
                <div class="col-sm-9">
                    @Html.NopDropDownListFor(model => model.ShippingMethodId, Model.AvailableShippingMethods)
                    @Html.ValidationMessageFor(model => model.ShippingMethodId)
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-3">
                    @Html.NopLabelFor(model => model.From)
                </div>
                <div class="col-sm-9">
                    @Html.NopEditorFor(model => model.From, Model.BaseWeightIn)
                    @Html.ValidationMessageFor(model => model.From)
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-3">
                    @Html.NopLabelFor(model => model.To)
                </div>
                <div class="col-sm-9">
                    @Html.NopEditorFor(model => model.To, Model.BaseWeightIn)
                    @Html.ValidationMessageFor(model => model.To)
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-3">
                    @Html.NopLabelFor(model => model.AdditionalFixedCost)
                </div>
                <div class="col-sm-9">
                    @Html.NopEditorFor(model => model.AdditionalFixedCost, Model.PrimaryStoreCurrencyCode)
                    @Html.ValidationMessageFor(model => model.AdditionalFixedCost)
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-3">
                    @Html.NopLabelFor(model => model.LowerWeightLimit)
                </div>
                <div class="col-sm-9">
                    @Html.NopEditorFor(model => model.LowerWeightLimit)
                    @Html.ValidationMessageFor(model => model.LowerWeightLimit)
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-3">
                    @Html.NopLabelFor(model => model.RatePerWeightUnit)
                </div>
                <div class="col-sm-9">
                    @Html.NopEditorFor(model => model.RatePerWeightUnit, Model.PrimaryStoreCurrencyCode)
                    @Html.ValidationMessageFor(model => model.RatePerWeightUnit)
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-3">
                    @Html.NopLabelFor(model => model.PercentageRateOfSubtotal)
                </div>
                <div class="col-sm-9">
                    @Html.NopEditorFor(model => model.PercentageRateOfSubtotal)
                    @Html.ValidationMessageFor(model => model.PercentageRateOfSubtotal)
                </div>
            </div>
        </div>
    </div>
</div>
